/**
 * 
 */
package com.runningfox.model;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;

import com.runningfox.humor.R;
import com.runningfox.logic.Logic;

/**
 * @author lhy
 * 用户配置
 * 首次启动用户名称为生成uuid
 */
public class Setting {
	
	public static String wifi=null;

	/**
	 * 用户性别
	 * 0:女
	 * 1：男
	 */
	public static int gender=1;
	
	/**
	 * 夜间模式
	 */
	public static boolean theme=false;
	/**
	 * 自动联网获取首页
	 */
	public static boolean autoConnect=true;
	
	/**
	 * latest version of content in the database;
	 */
	public static long contentVersion = -1;
	/**
	 * user id
	 */
	public static String imei = null;
	/**
	 * user name
	 */
	public static String name = null;
	/**
	 * user email
	 */
	public static String email = null;
	/**
	 * user id
	 * 初次运行生成的uuid
	 */
	public static String userid = null;
	public static String PREFS_NAME = "setting";

	
	public static void LoadSetting(Activity activity) {
		SharedPreferences pref = activity.getSharedPreferences(PREFS_NAME, 0);
		TelephonyManager telephonyManager = (TelephonyManager) activity
		.getSystemService(Context.TELEPHONY_SERVICE);
		userid = pref.getString("userid", Logic.genUserID());
		name = pref.getString("name", activity.getText(R.string.defaultusername).toString());
		imei = pref.getString("imei", telephonyManager.getDeviceId());
		email =pref.getString("email", null);
		gender = pref.getInt("gender", 1);
		autoConnect=pref.getBoolean("autoconnect", true);
		theme=pref.getBoolean("theme", true);
		saveSetting(activity);
	}

	public static void saveSetting(Activity activity) {
		SharedPreferences pref = activity.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = pref.edit();
		editor.putString("userid", userid);
		editor.putString("imei", imei);
		editor.putString("name", name);
		editor.putString("email", email);
		editor.putInt("gender", gender);
		editor.putBoolean("autoconnect", autoConnect);
		editor.putBoolean("theme", theme);
		editor.commit();
	}
}
